<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 设置变量foo，并置为test
        var foo = 'test';

        // 在if块中
        if (true) {
            var foo = 'new test';
        }
        console.log(foo); //new test
        function test() {
            var foo = 'old test';
        }
        test();
        console.log(foo); // foo还是等于new test


        function aa() {
            fo = 'test';
        }
        aa();
        console.log(window.fo == test); // false 隐式全局作用域
        
    </script>
</body>

</html>